
var $$g = function (name) {
    
    this.name = name;
    
    this.instance = function (data) {
        
        jQuery(this.name).jqGrid({
            "autowidth": true,
            "hoverrows":false,
            "viewrecords":true,
            "jsonReader":{"repeatitems":false,"subgrid":{"repeatitems":false}},
            "gridview":true,
            "rowNum":5,
            "colModel":[
                {"name":"No", "index":"No",       "align":"left", "hidden":true},
                {"name":"Item", "index":"Item",     "align":"left"},
                {"name":"Qty", "index":"Qty",     "align":"right", "editable":true},
                {"name":"Price", "index":"Price",   "align":"right"},
                {"name":"Amount", "index":"Amount",  "align":"right"}
            ],
            "data": data,
            "datatype":"local",
            "height":350,
//            "sortname": "id",
//            "viewrecords": true,
//            "sortorder": "asc",
            "loadError":function(xhr,status, err){ 
                try {jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,
                        '<div class="ui-state-error">'+ xhr.responseText +'</div>', 
                        jQuery.jgrid.edit.bClose,
                        {buttonalign:'right'}
                    );} catch(e) { alert(xhr.responseText);} 
                }
            });
        
            setTimeout(function() {
                SyntaxHighlighter.highlight({useScriptTags:false}, '')},
            100);
    };
    
    this.addRow = function (item, price) {
        
        var max = data.length + 1;
        var addItem = {
                "No":max,
                "Item": item,
                "Qty": 1,
                "Price": price, 
                "Amount": max
            }
        
        data.push(addItem);
        
        jQuery("#grid").jqGrid('addRowData',max,addItem);
        
    };
    
    this.delRow = function () {
        
    };
    
    this.update = function (data) {
        
    }
    
    this.exe = function () {
        
        alert("call " + this.name);
    };
    
    this.getSelRow = function () {
        
        var id = jQuery("#grid").jqGrid('getGridParam','selrow');
        
        return jQuery(this.name).jqGrid('getRowData',id);
    };
    
    this.delRow = function () {
        
        var id = jQuery(this.name).jqGrid('getGridParam','selrow');
        
        return jQuery(this.name).jqGrid('delRowData',id);
    };
    
    return this ;
};


